import {USER_LOGIN,INIT_USER } from './mutations-types.js'
export default {
   state: {
      // 登陆状态
      loginStatus:false,
      // token
      token:null,
      // 用户信息：用户头像|昵称
      userInfo:{}
   },
   mutations: {
      // 登录设置
      [USER_LOGIN](state,user){
         state.loginStatus = true;
			state.token = user.token;
			state.userInfo = user;
			//持久化存储==》本地存储
			localStorage.setItem('teaUserInfo',JSON.stringify(user));
      },
      // 登录状态读取
      [INIT_USER](state){
         let userInfo = Json.parse( localStorage.getItem('teaUserInfo') );
         if(userInfo){
            state.loginStatus = true;
			   state.token = user.token;
			   state.userInfo = user;
         }
      }
   },
   actions: {},
   getters: {},
}